FROM golang:1.21.4 AS builder

# micro serice application dir
ARG APP

# switch work dir
WORKDIR /build
# copy codes
COPY . .

# compile codes into /build/bin/
RUN mkdir -p bin \
    && GOPROXY=https://goproxy.cn GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/${APP} ./${APP}


FROM debian:stable-slim

RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates netbase \
    && rm -rf /var/lib/apt/lists/ \
    && apt-get autoremove -y \
    && apt-get autoclean -y

COPY --from=builder /build/bin /app

WORKDIR /app

# 启动命令
ENTRYPOINT ./${APP} --registry=${MICRO_REGISTRY} --registry_address=${MICRO_REGISTRY_ADDRESS}
